package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.ShoppingCarts;
import com.example.entity.vo.ShopCartsVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2024-09-13
 */
@Mapper
public interface ShoppingCartsMapper extends BaseMapper<ShoppingCarts> {
    @Select("select u.usr_id,c.shop_fig,g.list_goods_symbol,g.list_goods_price,g.list_goods_decimal,c.shop_id,c.keeper_id,c.goods_id,k.shop_keeper_title,g.list_goods_title,t.commodity_variety,g.list_goods_image_url,c.shop_number,c.shop_count from shopping_carts c join list_of_goods g on c.goods_id = g.list_goods_id join shop_keeper k on c.keeper_id = k.shop_keeper_id join sys_user u on c.usr_id = u.usr_id join commodity_type t on c.type_id = t.commodity_quantity where u.usr_id = #{usrId}")
    List<ShopCartsVo> selectAllByUsrId(@Param("usrId") Integer usrId);

    @Update("update shopping_carts set shop_fig = #{shopFig},shop_number = #{shopNumber} where shop_id = #{shopId};")
    Boolean updateGoodsId(@Param("shopFig") String shopFig,@Param("shopId") Integer shopId,@Param("shopNumber") Integer shopNumber);

    @Select("select COUNT(*) as numCount,shop_number,shop_id from shopping_carts where goods_id = #{goodsId} and usr_id = #{usrId}")
    ShopCartsVo selectAllByGoodsId(@Param("goodsId") Integer goodsId,@Param("usrId") Integer usrId);

    @Select("select COUNT(*) as numCount from shopping_carts where usr_id = #{usrId}")
    ShopCartsVo searchAllByUsrIdShopCartsVo(@Param("usrId") Integer usrId);

    @Select("select c.keeper_id,k.shop_keeper_title from shopping_carts c join list_of_goods g on c.goods_id = g.list_goods_id join shop_keeper k on c.keeper_id = k.shop_keeper_id join sys_user u on c.usr_id = u.usr_id join commodity_type t on c.type_id = t.commodity_quantity where u.usr_id = #{usrId} GROUP BY c.keeper_id")
    List<ShopCartsVo> selectAllByKeeperIdShopCartsVo(@Param("usrId") Integer usrId);

    @Delete("DELETE FROM shopping_carts where usr_id = #{usrId}")
    Boolean checkOutShopByUsrId(@Param("usrId") Integer usrId);
}
